let app = getApp();
Page({

  data: {
    movieId: '',
    movieInfo: [],
  },

  onLoad: function(options) {
    this.setData({
      movieId: options.id,
    });

    app.getGlobalData(app.globalData.doubanApi + 'subject/' + this.data.movieId).then((res) => {
      let apiData = res.data;
      wx.setNavigationBarTitle({
        title: apiData.title,
      })
      console.log(apiData.casts);
      //演员名字,图片
      let castsName = [], castsImg = [];
      apiData.casts.forEach(function(item){
        castsName.push(item.name);
        castsImg.push(item.avatars && item.avatars.small || '');
      });
      //电影详情信息
      let movieData = {
        title: apiData.title,
        date: apiData.pubdates[0],
        like: apiData.ratings_count || 0,
        commpentCount: apiData.reviews_count || 0,
        movieImg: apiData.images.small,
        average: apiData.rating.average || 0,
        directorName: apiData.directors[0].name,
        castsName: castsName,
        castsImg: castsImg,
        genres: apiData.genres.join('、'),
        summary: apiData.summary,
      };
      this.setData({
        movieInfo: movieData,
      });
    }, (err) => {

    });
  },

  //图片预览
  onPreviewImage(e){
    let previewImageSrc = e.currentTarget.dataset.src;
    console.log(previewImageSrc);
    wx.previewImage({
      current: previewImageSrc, // 当前显示图片的http链接
      urls: [previewImageSrc],// 需要预览的图片http链接列表
    });
  },
})